package com.shaoshaohuo.app.ui.ec;

import android.os.Bundle;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.constant.ExtraName;
import com.shaoshaohuo.app.entity.BaseEntity;
import com.shaoshaohuo.app.entity.Buyer;
import com.shaoshaohuo.app.entity.BuyerEntity;
import com.shaoshaohuo.app.net.HttpRequest.RequestListener;
import com.shaoshaohuo.app.net.RequestService;
import com.shaoshaohuo.app.ui.BaseActivity;
import com.shaoshaohuo.app.adapter.MerchantsDetailListAdapter;
import com.shaoshaohuo.app.view.TopbarView;
import com.shaoshaohuo.app.view.XListView;

public class MoreBuyerActivity extends BaseActivity {

	private TopbarView mTopbarView;

	private XListView mListView;
	
	private String id = ""; 
	private int buyersize = 50;
	private String cursor = "";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_more_buyer);
		initData();
		initView();
		setUpView();
		requestData();
	}

	private void initData() {
		id = getIntent().getStringExtra(ExtraName.id);
	}

	private void requestData() {
		startLoadingDialog();
		RequestService.getInstance().findBuyersMore(this, id, buyersize+"", cursor, BuyerEntity.class, new RequestListener() {
			
			@Override
			public void onSuccess(int requestCode, BaseEntity resultData) {
				dismissLoadingDialog();
				if(resultData.isOk()){
					BuyerEntity entity = (BuyerEntity) resultData;
					MerchantsDetailListAdapter<Buyer> adapter2 = new MerchantsDetailListAdapter<>(MoreBuyerActivity.this, entity.getData().getList(), false);
			        mListView.setAdapter(adapter2);
			        mListView.endLoadingMore("没有更多了");
				}else{
					showToast(resultData.getMsg());
				}
			}
			
			@Override
			public void onFailed(int requestCode, Exception error, String msg) {
				dismissLoadingDialog();
				showToast(R.string.please_check_network);
			}
		});
	}

	private void initView() {
		mTopbarView = (TopbarView) this.findViewById(R.id.topbar);
		mListView = (XListView) this.findViewById(R.id.listview_data_list);
	}

	private void setUpView() {
		mTopbarView.setCenterText("更多买家");
		mTopbarView.setLeftView(true, true);

		mListView.setPullLoadEnable(false);
		mListView.setPullRefreshEnable(false);
	}
	
}
